package com.zhang.first.day02;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @title: 物理分区算子
 * @author: zhang
 * @date: 2022/1/16 10:07
 */
public class Example8 {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //广播到下游所有物理分区（插槽）
        env
                .fromElements(1, 2, 3, 4).setParallelism(1)
                .broadcast()
                .print("broadcast:").setParallelism(4);

        //使用轮询平均分配到下游插槽
        env
                .fromElements(1, 2, 3, 4).setParallelism(1)
                .rebalance()
                .print("平均分配:").setParallelism(2);


        env
                .fromElements(1, 2, 3, 4).setParallelism(1)
                .shuffle()
                .print("随机分配:").setParallelism(2);

        //将所有数据分送到下游算子的第一个任务插槽
        env
                .fromElements(1, 2, 3, 4).setParallelism(1)
                .global()
                .print("global:").setParallelism(2);

        env.execute();
    }
}
